package GameLogic
{
	import BasicEngine.Dispatcher;
	import BasicEngine.Vector2D;
	import fl.events.ColorPickerEvent;
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import RobotPlayer.BaseRobot;
	import RobotPlayer.MoveEntity;
	public class ScanBeam extends Sprite
	{
		/**
		 * 雷达颜色
		 */
		public var Clr:int;
	    /**
	     * 雷达扫描线长度
	     */
		public var Len:int ;
		/**
		 * 雷达向量
		 */
		public var RadarAngle:Vector2D;
		/**
		 * 隐藏雷达
		 */
		public var Hide:Boolean;
		/**
		 * 转速
		 */
		public var Rev:Number;
		/**
		 * 对于雷达，只有三种动作，停止：0 顺时针转动：1 逆时针转动：2 
		 */
		public var Action:int;
		
		private var shape:Shape;
		private var maskt:Shape;
		private var timer:Number;
		
		
		public function ScanBeam(_robot:MoveEntity,_clr:int = 0x00ff00,_len:int= 150,_rev:Number = 0.05,_alpha:Number = 0.5)
		{
			Clr = _clr;
			Len = _len;
			Rev = _rev;
			shape = new Shape();
			Action = 1;
			for (var i:int = -3; i < 3; i++)
			{
				shape.graphics.lineStyle(1, Clr,(i+5)*0.2);
                shape.graphics.moveTo(0, 0);
                shape.graphics.lineTo(i*3, -Len);
			}
			this.alpha = _alpha;
			Hide = false;
			addChild(shape);
			RadarAngle = new Vector2D(1, 1).Normalize();
			_robot.Canvas.addChild(this);
			this.addEventListener(Event.ENTER_FRAME, Update);
		}
		
		public function Update(e:Event):void
		{
		    if (Game.Pause)
				return;
			if (Hide)
			   shape.visible = false;
			else
			   shape.visible = true;
			   
			switch(Action)
			{
				case 0:
					Stop();
					break;
				case 1:
					Running(true);
					break;
				case 2:
					Running(false);
					break;
				default:
					break;			
			}
			shape.rotation = RadarAngle.Angle * 180 / Math.PI;
	    }
		
		public function RoteToAngle(_a:int):void
		{
			if (Math.abs(RadarAngle.Angle - _a * Math.PI / 180) < 0.01)
			   Action = 0;
		}
		
		/**
		 * 雷达停止转动
		 */
		private function Stop():void
		{
			
		}
		/**
		 * 顺（逆）时针转动
		 * _rotationDirction: true 顺时针转动 false 逆时针转动
		 */
		private function Running(_rotationDirection:Boolean):void
		{
			if (_rotationDirection)
			{
				RadarAngle.Angle += Rev;
			}
			else
			{
				RadarAngle.Angle -= Rev;
			}
		}
		
		
	}
}